// olorSelArea.cpp : implementation file
//

#include "stdafx.h"
#include "AntX.h"
#include "ColorSelArea.h"
#include "NodePoint.h"
#include "AlgoritmHandler.h"


// ColorSelArea

IMPLEMENT_DYNAMIC(ColorSelArea, CStatic)

ColorSelArea::ColorSelArea(Color theColor, int theType)
{
	mCurColor=theColor;	 
	mType=theType;
}

ColorSelArea::~ColorSelArea()
{
}


BEGIN_MESSAGE_MAP(ColorSelArea, CStatic)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()



// ColorSelArea message handlers



void ColorSelArea::OnPaint()
{
	CPaintDC dc(this);  
	Graphics graphics(dc);
	graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);

	RECT rect;
	this->GetClientRect(&rect);

	int width=rect.right-rect.left;
	int height=rect.bottom-rect.top;

	SolidBrush solidBrush(mCurColor);
	graphics.FillRectangle(&solidBrush, rect.left, rect.top, width-1, height-1);
// 	//draw black border
// 	Pen pen(Color(0,0,0));
// 	graphics.DrawRectangle(&pen, rect.left, rect.top, width-1, height-1);
	
}

void ColorSelArea::SelectColor( Color theColor )
{
	mCurColor=theColor;
}

Color ColorSelArea::getCurrentColor()
{
	return mCurColor;
}

void ColorSelArea::OnLButtonDown(UINT nFlags, CPoint point)
{
	CColorDialog colorDlg;
	if (colorDlg.DoModal()==IDOK)
	{
		COLORREF selectColor=colorDlg.GetColor();
		mCurColor.SetFromCOLORREF(selectColor);
	}
	this->Invalidate();
	if (this->mType==NODECOLOR)
	{
		ApplyColorToNodes();
	}
	else
		ApplyColorToLines();
	this->GetParent()->Invalidate();

	CStatic::OnLButtonDown(nFlags, point);
}

void ColorSelArea::ApplyColorToNodes()
{
	AlgoritmHandler::setDefaultNodeColor(mCurColor);
}

void ColorSelArea::ApplyColorToLines()
{
	AlgoritmHandler::setDefaultLineColor(mCurColor);
}

 